Is there a problem with the control flow here?

by: PyLORD, 7 years ago

Last edited: 7 years ago

When I run this code everything but the third elif statement runs but everything is supposed to run from what I intended. If anyone can explain this to me that would be accepted.
<pre class='prettyprint lang-py'>
#!usr/bin/env python 3
import turtle

# Variable for the turtle
tina = turtle.Turtle()
tina.shape('turtle')

# Variable for the canvas
wx = turtle.Screen()
wx.bgcolor('turquoise')

number_list = [1,2,3,4,5,6,7,8,9,10]
angle = 60
x = -20
tina.color("green")
tina.speed(5)
#tina.circle()
#tina.c
while x < 20:
  for number in number_list:
      tina.forward(number*10)
      tina.left(angle)
      if number % 2 == 0:
        tina.color('red')
        tina.goto(0, 0)
        tina.left(angle + 1)
      elif number % 5 == 0:
        tina.goto(5, 5)
        tina.color('black')
        tina.left(angle + 2)
#THIS IS THE PART THAT DOES'NT RUN
-->  elif x == range(4, 8):
-->    tina.hideturtle()
-->    tina.color('white')
-->    tina.left(angle + 3)
      elif number % 3 == 0:
        tina.color('green')
        tina.goto(3, 3)
        tina.left(angle + 4)
</pre>



You must be logged in to post. Please login or register an account.



I think you mean
x in range(4, 8)
The range() function returns a list of integers, so in order for
x == range(...)
to evaluate True x would have to be a list. x is an integer, so it will never equate to any value that range() returns.

-scholzie 7 years ago
Last edited 7 years ago

You must be logged in to post. Please login or register an account.